function search(){
    var param={};
    param.username=$("#condition").find("[name=username]").val();
    var startDate=$("#condition").find("[name=startDate]").val();
    if(startDate!=""){
        param.startDate=startDate;
    }
    var endDate=$("#condition").find("[name=endDate]").val();
    if(endDate!=""){
        param.endDate=endDate;
    }
    $("#table").bootstrapTable("refresh",{query:param});
}
function fmtStatus(value){
    return value==1?"启用":"禁用";
}
function statusStyle(value){
    if(value==0){
        return {css:{background:'grey',color:'#fff'}};
    }else{
        return {css:{background:'#fff'}};
    }
}
$(document).ready(function(){
    initGrant();
    laydate.render({
        elem: '[name=startDate]'
    });
    laydate.render({
        elem: '[name=endDate]'
    });
});
function initGrant(){
    $("#grant").dialog({
        title:'用户授权',
        btnBind:function(){
            var rows1= $("#table").bootstrapTable("getSelections");
            var rows2=$("#roleTable").bootstrapTable("getSelections");
           var param="id="+rows1[0].id+"&roleId="+rows2[0].id;
           $.post(ctx+"sys/user/grant",param,function(msg){
               $("#grant").dialog("close");
               $("#table").bootstrapTable("uncheckAll");
               search();
               toastr.warning("信息提示",msg);
           });
        }
    });
}
function prepareGrant(){
   var rows= $("#table").bootstrapTable("getSelections");
   if(rows.length==0){
       swal("请选择一项待授权!");
       return;
   }
   var rid=rows[0].roleId;
    $("#roleTable").bootstrapTable("checkBy",{"field":"id","values":[rid]});
    $("#grant").dialog("open");
}

function exportFile(fmt){
    var obj={};
    $.ajax({
        url:ctx+"sys/role/list",
        dataType:'json',
        success:function(arr){
         /*  [{id:1001,name:'xxx'},{id:1002,name:'dsaf'}]
            {1001:'销售管理',{1002:"顾问"}*/

            $(arr).each(function(){
                obj[this.id]=this.name;
            });
            swal({
                title:'导出员工信息',
                text:'请选择角色：',
                input:'select',
                inputOptions:obj,
                confirmButtonText:"确定"
            }).then(function(id){
                location=ctx+"report?roleId="+id+"&format="+fmt;
            });
        }
    });
}
